import hashlib

def calculate_sig(request_path: str, params: dict, sk: str) -> str:
    # 对参数按参数名升序排序
    sorted_params = sorted(params.items(), key=lambda x: x[0])
    
    # 拼接排序后的参数（未编码）
    param_str = "&".join([f"{k}={v}" for k, v in sorted_params])
    
    # 拼接请求路径、参数和 SK
    string_to_sign = f"{request_path}?{param_str}{sk}"
    
    # 计算 MD5 值（小写）
    sig = hashlib.md5(string_to_sign.encode('utf-8')).hexdigest()
    
    return sig

# 示例数据
request_path = "/ws/geocoder/v1"
params = {
    "location": "28.7033487,115.8660847",
    "key": "5Q5BZ-5EVWJ-SN5F3-K6QBZ-B3FAO-*****"
}
sk = "SWvT26ypwq5Nwb5RvS8cLi6NSoH8HlJX"

# 计算签名
sig = calculate_sig(request_path, params, sk)
print("计算得到的签名:", sig)

if __name__ == "__main__":
    print("计算得到的签名:", sig)